/**
 * weapp-js
 * https://code.aliyun.com/jionglee/weapp_base.git
 * Copyright@ 2020 Motigo, Inc.
 * 
 */
Component({
    /**
     * 组件的属性列表
     */
    /**
     * 组件的初始数据
     */
    data: {
        items: [],
        width: 750,
        height: 562,
        visible: false,
    },
    options: null,
    ready() {},
    /**
     * 组件的方法列表
     */
    methods: {
        stopEvent() {},
        onHide() {
            this.setData({
                visible: false
            })
            this.options.complete && this.options.complete();
        },
        onTapImage() {},
        previewImage(opts) {
            this.setData({
                visible: true
            })
            this.options = opts;
            this.data.items = [];

            opts.urls.forEach(data => {
                let item = {};
                if (typeof data === 'string') {
                    item.src = data;
                } else if (typeof data === 'object') {
                    item.src = data.src;
                    item.desc = data.desc;
                } else {
                    console.error('invalid item:', data);
                }

                this.data.items.push(item);
            });

            this.setData({
                items: this.data.items,
                current: opts.current,
                width: opts.width || 750,
                height: opts.height || 562
            })
        }
    }
})
